package com.ruoyi.web.controller.system;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysWordReview;
import com.ruoyi.system.mapper.SysWordReviewMapper;

/**
 * 学员记录信息
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/system/review")
public class SysWordReviewController extends BaseController
{
    @Autowired
    private SysWordReviewMapper sysWordReviewMapper;

    /**
     * 获取复习记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:review:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysWordReview entity, Integer pageNum, Integer pageSize)
    {
    	String orderby = "A.id desc";
    	Long studentId = entity.getStudentId();
    	Long courseId = entity.getCourseId();
    	Long unitId = entity.getUnitId();
    	
    	String courseName = entity.getCourseName();
    	String unitName = entity.getUnitName();
    	String studentName = entity.getStudentName();
    	
    	pageSize = pageSize != null ? pageSize : 10;
    	pageNum = pageNum != null ? pageNum - 1 : 0;
    	Integer start = pageNum * pageSize;
    	Integer limit = pageSize;
        List<SysWordReview> list = sysWordReviewMapper.list(studentId, courseId, unitId, start, limit, orderby, courseName, unitName, studentName);
        Integer total = sysWordReviewMapper.count(studentId, courseId, unitId, courseName, unitName, studentName);
        return getDataTable(list, total.longValue());
    }

    /**
     * 导出复习记录
     */
    @PreAuthorize("@ss.hasPermi('student:record:export')")
    @PostMapping("/export")
    @Log(title = "复习记录", businessType = BusinessType.EXPORT)
    public void export(HttpServletResponse response, SysWordReview entity)
    {
    	String orderby = "A.id desc";
    	Long studentId = entity.getStudentId();
    	Long courseId = entity.getCourseId();
    	Long unitId = entity.getUnitId();
    	
    	String courseName = entity.getCourseName();
    	String unitName = entity.getUnitName();
    	String studentName = entity.getStudentName();

    	Integer start = null;
    	Integer limit = null;
        List<SysWordReview> list = sysWordReviewMapper.list(studentId, courseId, unitId, start, limit, orderby, courseName, unitName, studentName);
        ExcelUtil<SysWordReview> util = new ExcelUtil<SysWordReview>(SysWordReview.class);
        util.exportExcel(response, list, "学习记录");
    }
}